<?php
/**
---------------------------------------
Table album
---------------------------------------
*/

/**
count rows table album
*/
function getRowsAlbum() {
	$con = new ConnectDB();
	
	$sql = "Select COUNT(*) FROM album";
	return $con -> getvalueString($sql);
}

/**
get table album limit
*/
function getAlbumsLimit($start, $lenght) {
	$con = new ConnectDB();
	$sql = "Select album_key, album_name, album_description, album_view, album_datecreate, album_isuse FROM album ORDER BY album_datecreate DESC LIMIT ".$start.",".$lenght;
	return $con -> getvalueString($sql);
}

/**
get table album
*/
function getAlbums() {
	$con = new ConnectDB();
	$tbl = " album";
	$fn = array('album_key', 'album_name', 'album_description', 'album_view', 'album_datecreate', 'album_isuse');
	$condetion = array('album_isuse' => '1');
	return $con -> getvalue($tbl, $fn, $condetion);
}

/**
get table album
*/
function getAlbum($idalbum) {
	$con = new ConnectDB();
	$tbl = "album";
	$fn = array('album_key', 'album_name', 'album_description', 'album_view', 'album_datecreate');
	$condetion = array('album_key' => $idalbum);
	return $con -> getvalue($tbl, $fn, $condetion);
}

/**
insert table album
*/
function insertAlbum($id, $namealbum, $description) {
	$con = new ConnectDB();
	$tbl = "album";
	$fn = array('album_key' => $id, 'album_name' => $namealbum, 'album_description' => $description, 'album_view' => '1', 'album_datecreate' => time());
	return $con -> insert($tbl, $fn);
}

/**
display table album for id
*/
function displayAlbum($id, $isuse) {
	$con = new ConnectDB();
	$tbl = "album";
	$fn = array('album_isuse' => $isuse);
	$conf = array('album_key' => $id);
	return $con -> update($tbl, $fn, $conf);
}
/**
update display list id album
*/
function displayAlbumList($ids, $isuse) {
	$con = new ConnectDB();
	$tbl = "album";
	$fn = array('album_isuse' => $isuse);
	$rowid = 'album_key';
	return $con -> updatedels($tbl, $fn, $rowid, $ids);
}

/**
delete table album for list id
*/
function deleteListAlbum($ids) {
	$con = new ConnectDB();
	$tbl = "album";
	$rowid = 'album_key';
	return $con -> deletelists($tbl, $rowid, $ids);
}

/**
delete table album for id
*/
function deleteAlbum($id) {
	$con = new ConnectDB();
	$tbl = "album";
	$fn = array('album_key' => $id);
	return $con -> delete($tbl, $fn);
}

/**
update album name and descripton
*/
function updateDescriptonAlbum($id, $name, $content) {
	$con = new ConnectDB();
	$tbl = "album";
	$fn = array('album_name' => $name, 'album_description' => $content);
	$conf = array('album_key' => $id);
	return $con -> update($tbl, $fn, $conf);
}


/** 
--------------------------------------
Table album_detail
--------------------------------------

*/
/**
get table album_detail
*/
function getAlbumDetails($idalbum) {
	$con = new ConnectDB();
	$tbl = "album_detail";
	$fn = array('album_detail_key', 'album_key', 'album_detail_name', 'album_detail_description', 'album_detail_link_image', 'album_detail_dateupdate');
	$condetion = array('album_key' => $idalbum);
	return $con -> getvalueorderby($tbl, $fn, $condetion, 'album_detail_dateupdate');
}

/**
insert table album_detail
*/
function insertAlbumDetail($id, $idalbum, $namephoto, $description, $linkimage) {
	$con = new ConnectDB();
	$tbl = "album_detail";
	$fn = array('album_detail_key' => $id, 'album_key' => $idalbum, 'album_detail_name' => $namephoto, 'album_detail_description' => $description, 'album_detail_link_image' => $linkimage, 'album_detail_dateupdate' => time());
	return $con -> insert($tbl, $fn);
}

/**
delete table album_detail for list id album
*/
function deleteAlbumDetailByListIDAlbum($ids) {
	$con = new ConnectDB();
	$tbl = "album_detail";
	$rowid = 'album_key';
	return $con -> deletelists($tbl, $rowid, $ids);
}


/**
delete table album_detail for id album
*/
function deleteAlbumDetailByIDAlbum($id) {
	$con = new ConnectDB();
	$tbl = "album_detail";
	$fn = array('album_key' => $id);
	return $con -> delete($tbl, $fn);
}



/**
update photo descripton
*/
function updateDescriptonAlbumDetail($id, $content) {
	$con = new ConnectDB();
	$tbl = "album_detail";
	$fn = array('album_detail_description' => $content);
	$conf = array('album_detail_key' => $id);
	return $con -> update($tbl, $fn, $conf);
}

/**
delete album detail by id photo
*/
function deleteAlbumDetail($id) {
	$con = new ConnectDB();
	$tbl = "album_detail";
	$fn = array('album_detail_key' => $id);
	return $con -> delete($tbl, $fn);
}





/**
get table album limit
*/
function getAlbumDetailsLimitIndex($type, $start, $lenght) {
	$con = new ConnectDB();
	$sql = "Select d.album_detail_key, d.album_key, a.album_name, d.album_detail_name, d.album_detail_description, d.album_detail_link_image FROM album as a, album_detail as d WHERE d.album_key=a.album_key AND d.album_detail_isuse='1'" ;
	if ($type != "") {
		$sql .= " AND d.album_key='".$type."'";
	}
	$sql .= "ORDER BY d.album_detail_dateupdate DESC LIMIT ".$start.",".$lenght;
	return $con -> getvalueString($sql);
}
?>